<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onRowSelectChange="selectChange"
      columnsRef="jzySeries"
      :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>
    <Drawer
      :title="dialogTitle"
      :visible.sync="showAddNew"
      :width="920"
      :closable=true
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <accessoriesAddressDLR  :type="handleType" :rowData="formData"  @close="dialogClose" />
    </Drawer>
  </div>
</template>

<script>
  import accessoriesAddressDLR from './accessoriesAddressDLR'
  import { dictionary } from '@/utils/dictMixin';
  import { getShlist } from '@/api/part/accessories/index';
    export default {
      name: "accessoriesSh",
      mixins: [dictionary],
      components: {
        accessoriesAddressDLR
      },
      data() {
        return{
          topFilterList: this.createTopFilterList(),
          columns: this.createTableColumns(),
          fetchApi: getShlist,
          fetchParams: null,
          dialogTitle:'',
          visibleDrawer: false,
          title: '新增',
          type:'',
          formData:{},
          rowSelectData: [],
          showAddNew:false,
          handleType:'',
          conf:{ add: '新增', edit: '编辑', sh: '审核' }
        };
      },
      created() {
      },
      methods: {
        dialogedit(row){
          this.handleType = 'sh';
          this.formData = row;
          this.showHandler();
        },
        showHandler() {
          this.dialogTitle = `配件地址${this.conf[this.handleType]}`;
          this.showAddNew = true;
        },
        dialogClose(){
          this.showAddNew = false
            // 重新加载
          this.fetchParams = { ...this.fetchParams };
        },
        createTopFilterList() {
          return[
            {
              type: 'INPUT',
              label: '经销商代码',
              fieldName: 'xsjxhdm'
            },
            {
              type: 'INPUT',
              label: '经销商名称',
              fieldName: 'xsjxhmc'
            },
            {
              type: 'INPUT',
              label: '联系人',
              fieldName: 'xtlxry'
            },
            {
              type: 'INPUT',
              label: '详细地址',
              fieldName: 'xsxxdz'
            },
            {
              type: 'SELECT',
              label: '地址性质',
              fieldName: 'xsdzxz',
              placeholder: '请选择...',
              itemList: this.createDictList('5001')
            },
            {
              type: 'SELECT',
              label: '是否有效',
              fieldName: 'xtqybz',
              placeholder: '请选择...',
              itemList:this.createDictList('1004')
            },
            {
              type: 'SELECT',
              label: '申请类型',
              fieldName: 'xssqlx',
              placeholder: '请选择...',
              itemList:this.createDictList('5002')
            },
            {
              type: 'INPUT',
              label: '联系电话',
              fieldName: 'xtlxdh'
            }
          ]
        },
        createTableColumns () {
          return [
            {
              title: '序号',
              dataIndex: 'index',
              width: 70,
              sorter: true,
              render: props => {
                return <span>{props.row.index + 1}</span>;
              }
            },
            {
              title: '操作',
              dataIndex: 'column-action',
              width: 60,
              fixed: 'left',
              render: (props, h) => {
                return (
                  <div>
                  <el-button size="mini" type="text" onClick={() => this.dialogedit(props.row)}>
                审核
                </el-button>
                </div>
              );
              }
            },
            {
              title: '经销商代码',
              dataIndex: 'xsjxhdm',
              sorter: true,
            },
            {
              title: '经销商名称',
              dataIndex: 'xsjxhmc',
              sorter: true,
            },
            {
              title: '申请类型',
              dataIndex: 'xssqlx',
              sorter: true,
              render: props => {    //编码转汉字
                return <span>{this.createDictText(props.row.xssqlx, '5002')}</span>;
              }
            },
            {
              title: '详细地址',
              dataIndex: 'xsxxdz',
              sorter: true,
            },
            {
              title: '地址性质',
              dataIndex: 'xsdzxz',
              sorter: true,
              render: props => {    //编码转汉字
                return <span>{this.createDictText(props.row.xsdzxz, '5001')}</span>;
              }
            },
            {
              title: '联系人',
              dataIndex: 'xtlxry',
              sorter: true,
            },
            {
              title: '联系电话',
              dataIndex: 'xtlxdh',
              sorter: true,
            },
            {
              title: '创建人',
              dataIndex: 'createnaem',
              sorter: true,
            },
            {
              title: '创建时间',
              dataIndex: 'createdAt',
              dateFormat: 'yyyy-MM-dd hh:mm:ss',
              sorter: true,
            },
            {
              title: '更新人',
              dataIndex: 'updatenaem',
              sorter: true,
            },
            {
              title: '更新时间',
              dataIndex: 'updatedAt',
              dateFormat: 'yyyy-MM-dd hh:mm:ss',
              sorter: true,
            },
            {
              title: '是否有效',
              dataIndex: 'xtqybz',
              sorter: true,
              render: props => {    //编码转汉字
                return <span>{this.createDictText(props.row.xtqybz, '1004')}</span>;
              }
            }
          ]
        },
        selectChange(val) {
          console.log('val', val);
          this.rowSelectData = val;
        },
        pjlxSelect(val) {
          // 配件属性接口
        },
        changeHandle(val) {
          this.fetchParams = Object.assign({}, val);
          console.info('dhajkshdjkah')
          console.info(this.fetchParams)
        },
        collapseHandle() {
          this.$nextTick(() => {
            this.BaseTable.EXECUTE_RESET_HEIGHT();
          });
        },
      }
    }
</script>

<style scoped>

</style>
